﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace StyleMVVM.Validation.Impl.Fluent.Operators
{
	public class ContainsOperator<T> : BinaryOperator<T>
	{
		public ContainsOperator()
		{
			expressionMethod = GetType().GetTypeInfo().GetDeclaredMethod("Operate");
		}

		public static bool Operate(object leftValue, object rightValue)
		{
			IEnumerable<object> leftList = leftValue as IEnumerable<object>;
			IEnumerable<object> rightList = rightValue as IEnumerable<object>;

			if (leftList != null && rightList != null)
			{
				foreach (object o in rightList)
				{
					if (!leftList.Contains(o))
					{
						return false;
					}
				}

				return true;
			}

			return false;
		}
	}
}